﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using IRepository;//引用接口的命名空间
using Repository;//引用实现接口的命名空间
using WorkModel;
using Microsoft.AspNetCore.Authorization;

namespace WorkApi.Controllers
{
    [Route("api/[controller]")]
    
    [ApiController]
    public class UserinfouController : ControllerBase
    {
        //依赖注入接口(相当于实例化Bll)
        private IUserinfouRepository ma = null;
        //构造函数
        public UserinfouController(IUserinfouRepository mb)
        {
            ma = mb;
        }
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="UserPwd"></param>
        /// <returns></returns>
        [Route("Longin")]
        [HttpPost]
        public int UserLongin([FromForm] string UserName, [FromForm] string UserPwd, [FromForm] string name)
        {
            var n = ma.UserCheck(name);
            if (n != null)
            {

            }


            int m = ma.UserLongin(UserName, UserPwd);
            if (m > 0)
            {
                return m;
            }
            else
            {
                return m;
            }
        }

        /// <summary>
        /// 用户显示方法
        /// </summary>
        /// <param name="name"></param>
        /// <param name="cIndex"></param>
        /// <param name="pSize"></param>
        /// <returns></returns>
        [Authorize]
        [Route("Show")]
        [HttpGet]
        public IActionResult UserShow(string name = "", int cIndex = 1, int pSize = 2)
        {
            name += "";
            int rCount;
            List<Userinfou> li = ma.UserShow(name, cIndex, pSize, out rCount);
            return Ok(new { data = li, code = 0, count = rCount });
        }
        /// <summary>
        /// 删除用户方法
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// 
        [Route("Delete")]
        [HttpPost]
        public int UserDelete(string id)
        {
            int n = ma.UserDelete(id);
            return n;
            //return Ok(new { data = n});
        }
        /// <summary>
        /// 用户注册(添加)
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        [Route("Add")]
        [HttpPost]
        public int UserAdd([FromForm] Userinfou m)
        {
            int n = ma.UserAdd(m);
            return n;
            //return Ok(new { data = n, code = 0 });
        }
        /// <summary>
        /// 用户修改
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        [Route("Upt")]
        [HttpPost]
        public int UserUpt([FromForm] Userinfou m)
        {
            int n = ma.UserUpt(m);
            return n;
        }
        /// <summary>
        /// 用户反填
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        [Route("Fan")]
        [HttpGet]
        public IActionResult UserFan(int id)
        {
            var n = ma.UserFan(id);
            return Ok(new { data = n, code = 0 });
        }
       

       
    }
}
